//
//  BVModifyMobileViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/10/21.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVModifyMobileViewController.h"
#import "NSString+BVValiMobile.h"

@interface BVModifyMobileViewController ()
@property (weak, nonatomic) IBOutlet UITextField *mobileTextField;

@end

@implementation BVModifyMobileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"电话"];
    [self setupRightBarButtonItem];
    [self.navItem setEnabled:NO];
    [self.navItem setTitleColor:[UIColor BVLineGrayColor] forState:UIControlStateNormal];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.mobileTextField setPlaceholder:self.user.mobile.length == 0 ? @"您的手机号" : self.user.mobile];
}

#pragma mark -
#pragma mark - save
- (void)confirmSaveClick {
    [self.hud show:YES];
    [JDStatusBarNotification showWithStatus:@"正在保存" styleName:JDStatusBarStyleDefault ];
    [self.mineTool modifyUserMobile:self.mobileTextField.text success:^{
        [self.hud hide:YES];
        [JDStatusBarNotification showWithStatus:@"保存成功" dismissAfter:2.0 styleName:JDStatusBarStyleSuccess];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [self.hud hide:YES];
        [self showError:@"保存失败"];
    }];
}
- (IBAction)textFieldChange:(UITextField *)textField  {
    if ([textField.text isEqualToString:self.user.mobile] || textField.text.length == 0 || ![NSString valiMobile:textField.text]) {
        [self.navItem setEnabled:NO];
        [self.navItem setTitleColor:[UIColor BVLineGrayColor] forState:UIControlStateNormal];
    } else {
        [self.navItem setEnabled:YES];
        [self.navItem setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
}

- (IBAction)tap:(id)sender {
    [self.view endEditing:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
